package com.koron.plan.web.patrolplan.bean.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.koron.bean.base.BaseBean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Date;

/**
 * 排班班次(ClassesShift)表实体类
 *
 * @author jzp
 * @since 2021-10-20
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ApiModel(value = "排班班次", description = "ClassesShift")
public class ClassesShift extends BaseBean {

    /**
     * 排班方案id
     */
    @ApiModelProperty("排班方案id")
    private String scheduleId;

    /**
     * 班别名称
     */
    @ApiModelProperty("班别名称")
    private String name;

    /**
     * 是否空白班，0不是，1是
     */
    @ApiModelProperty("是否空白班，0不是，1是")
    private Integer blanked;

    /**
     * 值班开始时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    @ApiModelProperty("值班开始时间")
    private Date startTime;

    /**
     * 值班结束时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    @ApiModelProperty("值班结束时间")
    private Date endTime;

    /**
     * 值班状态，数据字典：operation_shift_status
     */
    @ApiModelProperty("值班状态，数据字典：operation_shift_status")
    private Integer status;

    /**
     * 排序
     */
    @ApiModelProperty("排序")
    private Integer sort;

    public Date computeEndTime(String duration) {
        Instant instant = this.startTime.toInstant();
        Instant plus1 = instant.plus((long) (Double.parseDouble(duration) * 60), ChronoUnit.MINUTES);
        this.endTime = Date.from(plus1);
        return this.endTime;
    }

}
